package com.rankeiot.core.tags;

import com.jfinal.template.Directive;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;
import com.rankeiot.core.util.JSONUtil;

import java.io.IOException;

/**
 *
 * 用于在Enjoy模板中输出JSON
 */
public class JsonTag extends Directive {
    @Override
    public void exec(Env env, Scope scope, Writer writer) {
        Object obj= exprList.getFirstExpr().eval(scope);
        try {
            writer.write(JSONUtil.toJSONString(obj));
           // writer.write(JSON.toJSONString(obj, SerializerFeature.WriteMapNullValue));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
